<!-- 验收 -->
<template>
  <el-descriptions :column="2" size="large" class="td-item">
    <el-descriptions-item label-class-name="right-align" label='项目名称'>
      <span class="text--info subtext">{{projectInfo.projectName}}</span>
    </el-descriptions-item>

    <el-descriptions-item label-class-name="right-align" label='评审项目阶段'>
      <span class="text--info subtext">{{processName(projectInfo?.stageStatus)}}</span>
    </el-descriptions-item>

    <el-descriptions-item label-class-name="right-align" label='项目验收报告'>
      <div v-if="checkDetail?.accReportAttachmentArr?.length" class="file-wrap">
        <p
          class="text--info download-link subtext"
          v-for="(obj, index) in checkDetail?.accReportAttachmentArr"
          :key="index"
          @click.prevent="handlePreview(obj)"
        >
          <el-link :underline="false" icon="el-icon-folder">{{ obj?.fileName }}</el-link>
        </p>
      </div>
      <div class="text--info subtext file-wrap" v-else> - </div>
    </el-descriptions-item>

    <el-descriptions-item label-class-name="right-align" label='项目经费决算报告'>
      <div v-if="checkDetail?.finaReportAttachmentArr?.length" class="file-wrap">
        <p
          class="text--info download-link subtext"
          v-for="(obj, index) in checkDetail?.finaReportAttachmentArr"
          :key="index"
          @click.prevent="handlePreview(obj)"
        >
          <el-link :underline="false" icon="el-icon-folder">{{ obj?.fileName }}</el-link>
        </p>
      </div>
      <div class="text--info subtext file-wrap" v-else> - </div>
    </el-descriptions-item>
    
    <el-descriptions-item label-class-name="right-align" label='项目申报材料'>
      <div v-if="projectInfo?.kyFilesArr?.length" class="file-wrap">
        <p
          class="text--info download-link subtext"
          v-for="(obj, index) in projectInfo?.kyFilesArr"
          :key="index"
          @click.prevent="handlePreview(obj)"
        >
          <el-link :underline="false" icon="el-icon-folder">{{ obj?.fileName }}</el-link>
        </p>
      </div>
      <div class="text--info subtext file-wrap" v-else> - </div>
    </el-descriptions-item>
  </el-descriptions>
</template>

<script lang="ts" setup>
import axios from "axios";
import { onMounted, ref, watch } from "vue";
import { useRoute } from "vue-router";
import { storageLocal } from "/@/utils/storage";
import {processStatus}  from  "/@/utils/globalConstant";
const props = defineProps({
  projectInfo: {
    type: Object
  },
});
const route = useRoute();
const info = ref({});
const checkDetail = ref({})
const baseUrl = ref(import.meta.env.VITE_BASE_URL);
watch(
  () => props.projectInfo,
  newvalue => {
    info.value = newvalue;
  },
  { immediate: true }
);

onMounted(() => {
  info.value = props.projectInfo; 
});

//获取项目验收详情
const initProjectInfo = async () => {
  const queryId = route.query?.projectManageId ?? "";
  const getExpertUrl = `${baseUrl.value}/rdms-admin/project/stage/acceptance/detail/${queryId}`;
  const headers = { headers: {Authorization: storageLocal.getItem("rdms-info")?.accessToken}}
  try {
    const res = await axios.post(getExpertUrl,'',headers);
    if (res.status === 200) {
      checkDetail.value = res.data?.data;
    }
  } catch (err) {
    console.log(err);
  }
};

const handlePreview = (item: any) => {
  if (item.response) {
    window.open(
      `${location.origin}${location.pathname}#/online?uuidFile=${item?.response.data.uuidFile}&fileName=${item?.response.data.fileName}`
    );
  } else {
    window.open(
      `${location.origin}${location.pathname}#/online?uuidFile=${item.uuidFile}&fileName=${item.fileName}`
    );
  }
};

const processName = (stageStatus) => {
  return processStatus.get(+stageStatus)
}
initProjectInfo()
</script>

<style lang="scss" scoped>
  .file-wrap{
    display: inline-block;
    vertical-align: top
  }
</style>
